<#include "/common/head.html"/>
<div id="subLayout" class="easyui-layout" data-options="fit:true, border:false">
	<div data-options="region:'center', border:false">   
    <table id="dg"></table>
    <div id="tb" style="padding:2px 5px;">
        <div class="wrap_search">
        				<span class="search_item">
				            	<span class="item_text">入库单编号: </span>
				            	<span class="item_obj">
				            		<input class="easyui-textbox" type="text" name="in_no" id="in_no" value=""/>
				            	</span>    
				        </span>		        		
			            <span class="search_item">
				            	<span class="item_text">入库单名称: </span>
				            	<span class="item_obj">
				            		<input class="easyui-textbox" type="text" name="in_name" id="in_name" value=""/>
				            	</span>    
				        </span>
		            	<span class="search_item">
			            	<span class="item_text">入库类型: </span>
			            	<span class="item_obj">
			            		<input class="easyui-combobox" name="in_type" id="in_type" value="" style="width:100px" data-options="
			            				valueField: 'id',
        								textField: 'text',
			            				data: [
			            					{id:'', text:'-请选择-'}<#list dictDatain_type.keySet() as key>,{id:'${key}', text:'${dictDatain_type.get(key)}'}</#list>
			            				]
			            			" />
			            	</span>    
			            </span>
		            	<span class="search_item">
			            	<span class="item_text">所属仓库: </span>
			            	<span class="item_obj">
			            		<input class="easyui-combobox" name="storage_no" id="storage_no" value="" style="width:100px" data-options="
			            				valueField: 'id',
        								textField: 'text',
			            				data: [
			            					{id:'', text:'-请选择-'}<#list dictDatastorage_no.keySet() as key>,{id:'${key}', text:'${dictDatastorage_no.get(key)}'}</#list>
			            				]
			            			" />
			            	</span>    
			            </span>
		        		
			        		<span class="search_item search_between">
				                <span class="item_text">填单时间: </span>
				                <span class="item_obj">
				                    <input class="easyui-datebox" name="_start_in_time" id="_start_in_time" value=""/> ～ <input class="easyui-datebox" name="_end_in_time" id="_end_in_time" value=""/>
				                </span>
				            </span>
		            	<span class="search_item">
			            	<span class="item_text">单据类型: </span>
			            	<span class="item_obj">
			            		<input class="easyui-combobox" name="operate_type" id="operate_type" value="" style="width:100px" data-options="
			            				valueField: 'id',
        								textField: 'text',
			            				data: [
			            					{id:'', text:'-请选择-'}<#list dictDataoperate_type.keySet() as key>,{id:'${key}', text:'${dictDataoperate_type.get(key)}'}</#list>
			            				]
			            			" />
			            	</span>    
			            </span>	
			            <span class="search_item">
			            	<span class="item_text">单据状态: </span>
			            	<span class="item_obj">
			            		<input class="easyui-combobox" name="in_status" id="in_status" value="" style="width:100px" data-options="
			            				valueField: 'id',
        								textField: 'text',
			            				data: [
			            					{id:'', text:'-请选择-'}<#list dictDatain_status.keySet() as key>,{id:'${key}', text:'${dictDatain_status.get(key)}'}</#list>
			            				]
			            			" />
			            	</span>    
			            </span>
        </div>
        <div style="text-align: left; margin:6px;">
            <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" plain="true" onclick="add()">增加</a>
            <a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true" onclick="update()">编辑</a>
            <a href="javascript:void(0)" class="easyui-linkbutton delBtn" iconCls="glyphicon-remove" plain="true" onclick="del()">删除</a>
            <a href="javascript:void(0)" class="easyui-linkbutton onPublishBtn color1" iconCls="glyphicon-hand-up" plain="true" onclick="publish()">审核入库单</a>
            <a href="javascript:void(0)" class="easyui-linkbutton detailBtn color1" iconCls="glyphicon-map-marker" plain="true" onclick="detail()">查看入库单</a>
            <a href="javascript:void(0)" class="easyui-linkbutton inStorageBtn color1" iconCls="glyphicon-log-in" plain="true" onclick="inStorage()">执行入库</a>
            <!-- <a href="javascript:void(0)" class="easyui-linkbutton exportBtn" iconCls="glyphicon-export" plain="true" onclick="exportCsv()">导出</a>-->
            <!-- <a href="javascript:void(0)" class="easyui-linkbutton importBtn" iconCls="glyphicon-import" plain="true" onclick="importCsv()">导入</a>--> 
            <div id="searchBtnWrap" style="float:right; padding-right:5px;">
                <a href="javascript:void(0)" class="easyui-linkbutton color1" iconCls="glyphicon-search" onclick="zcurdSearch(this)">搜索</a>
                <a href="javascript:void(0)" class="easyui-linkbutton color2" iconCls="glyphicon-repeat" onclick="flushPage()">重置</a>
            </div>
        </div>
    </div>
  </div>
    <div data-options="region:'east',split:true, border:false, collapsed:true, width:window.subPageWidth||'40%', title:window.subPageTitle||'子页面'">
    	<iframe id="subIframe" class="easyui-panel" data-options="fit:true,border:false"></iframe>
    </div>
</div>    

<script type="text/javascript">
var datagrid = $("#dg");

var dgOptions = {
        rownumbers:true,
    	fit:true,
    	border:false,        
    	url:'listData',
    	method:'post',
    	toolbar:'#tb',
    	pageSize: 20,
    	pagination:true,
    	multiSort:true,
        queryParams: getInitParam(),
        
        columns: [[
		         {field:'id', checkbox:true}
		         ,{field:'in_no', title: '入库单编号', width:100, sortable: true}
	           	 ,{field:'in_barcode', title: '入库单条码', width:100, sortable: true}
	           	 ,{field:'in_name', title: '入库单名称', width:200, sortable: true}
	           	 ,{field:'in_type', title: '入库类型', width:80, sortable: true}
	           	 //,{field:'order_no', title: '订单编号', width:120, sortable: true}
	           	 ,{field:'storage_no', title: '所属仓库', width:80, sortable: true}
	           	 //,{field:'sup_num', title: '供应商编号', width:120, sortable: true}	           	 
	           	 ,{field:'create_user', title: '填单人员', width:80, sortable: true}
	           	 ,{field:'in_time', title: '填单时间', width:140, sortable: true}
	           	 //,{field:'audit_user', title: '审核人员', width:120, sortable: true}
	           	 //,{field:'audit_time', title: '审核时间', width:120, sortable: true}
	           	 //,{field:'print_user', title: '打印人员', width:120, sortable: true}
	           	 //,{field:'print_time', title: '打印时间', width:120, sortable: true}
	           	 ,{field:'operate_type', title: '单据类型', width:80, sortable: true}	
	           	 ,{field:'in_status', title: '单据状态', width:80, sortable: true}
	           	 //,{field:'in_batch', title: '批次', width:120, sortable: true}
	           	 ,{field:'operate', title: '操作', width:140, 
	             	formatter: function(value, row, index){	             		
	     			  	return '<a class="easyui-linkbutton color2" name="opera" href="javascript:void(0)" onclick="btnClick5(' + index + ')"></a>';
	     		  	}	     		    
	             }
	           ]],
	    onLoadSuccess:function(data){    
    	            $("a[name='opera']").linkbutton({text:'入库单物料明细',plain:true,iconCls:'glyphicon-th-list'});    
    	    	}, 
		rowStyler:function(index,row){
					if (row.in_status=='草稿'){
						return 'background-color:green;color:#fff;';
					}
				}
	};
$(function() {
	handleAuthDataRule();
	datagrid.datagrid(dgOptions);
});

function zcurdSearch() {
	var param = zcurdGetParam();
	datagrid.datagrid("load", {
		queryParams: param
	})
}

function zcurdGetParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param[$(item).attr("name")] = $(item).val();	
		}
	});
	return param;
}

function getInitParam() {
	var param = {};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param["queryParams[" + $(item).attr("name") + "]"] = $(item).val();	
		}
	});
	return param;
}

var initPara = zcurdGetParam();
function add() {
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("增加成功！");
		datagrid.datagrid("load");
	}
	top.openWindow("入库单主表-增加", getCurrUrl("addPage") + "?" + $.param(initPara), {size: '800x500'});
}

function update() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要编辑的一条数据！");
		return;
	}
	if(rowsSel[0].in_status=="草稿"){
		var id = rowsSel[0].id;
		top.window.subPage.loadCurrDatagrid = function() {
			showMsg("更新成功！");
			datagrid.datagrid("reload");
		}
		top.openWindow("入库单主表-编辑", getCurrUrl("updatePage") + "?id=" + id, {size: '600x400'});
	}
	else{
		showWarnMsg("已经审核完成，不能编辑！");
	}
}

function del() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("必须选择一个入库单！");
		return;
	}
	if(rowsSel[0].in_status=="已发布"||rowsSel[0].in_status=="已完成"){
		showWarnMsg("只能删除“草稿”状态的入库单！");
		return;
	}	
	confirmMsg("确认删除？", function() {
		$.post("delete", {id: rowsSel[0].id}, function(data) {
			showMsg("删除成功！");
			datagrid.datagrid("reload");
		});
	});
}

function detail() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要查看的一条入库单！");
		return;
	}
	var id = rowsSel[0].id;
	top.openWindow("入库单主表-详情", getCurrUrl("detailPage") + "?id=" + id, {size: '600x600'});
}

function exportCsv() {
	var option = datagrid.datagrid("options");
	var param = option.queryParams;
	param.sortName = option.sortName;
	param.sortOrder = option.sortOrder;
	window.location.href = "exportCsv?" + $.param(param);
}
function importCsv() {
	top.window.subPage.loadCurrDatagrid = function() {
		showMsg("导入成功！");
		datagrid.datagrid("load");
	}
	top.openWindow("入库单主表-导入", getCurrUrl("importCsvPage") + "?" + $.param(initPara), {size: '600x500'});
}
//审核入库单
function publish(){
	
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择需要审核的一条数据！");
		return;
	}
	if(rowsSel[0].in_status=="草稿"){
		var id = rowsSel[0].id;
		top.window.subPage.loadCurrDatagrid = function() {
			showMsg("更新成功！");
			datagrid.datagrid("reload");
		}
		top.openWindow("入库单主表-审核", getCurrUrl("pubishPage") + "?id=" + id, {size: '800x500'});
	}
	else{
		showWarnMsg("已经审核完成，请勿重复审核！");
	}
}
//执行入库操作
function inStorage(){
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择一个入库单！");
		return;
	}
	if(rowsSel[0].in_status=="草稿"||rowsSel[0].in_status=="已完成"){
		showWarnMsg("请确认入库单状态为已发布！");
		return;
	}
	var id = rowsSel[0].id;
	confirmMsg("确认入库？", function() {
		$.post("exeuInStorage", {id: id}, function(data) {
			//需要加载mask
			showWarnMsg(data.msg);
			datagrid.datagrid("reload");
		});
	});
	
}
//按钮事件
window.btnClick5 = function(index) {
 var row = datagrid.datagrid("getRows")[index];
  var url = basePath + "/wms/inStorageDetail/listPage?id=" + row.id+"&instatus="+row.in_status;
  _openSubPage(url);
};

/**
 * 打开子页
 */
var _openSubPageFlag = false;
function _openSubPage(pageUrl) {
	if(!_openSubPageFlag) {
		$("#subLayout").layout("expand", "east");
		setTimeout(function() {
			$("#subIframe").attr("src", pageUrl);
		}, 600);
		_openSubPageFlag = true;
	}else {
		$("#subIframe").attr("src", pageUrl);
	}
}

//扩展js
var operateWidth = 100;
var subPageWidth = "55%";
var subPageTitle = "入库物料列表";
dgOptions.singleSelect=true;;

//扩展js
</script>

<#include "/common/dialogWindow.html"/>
<#include "/common/foot.html"/>
